<?php
namespace App\Models;

use Faker\Core\Number;

/**
 * Model StudentCard
 *
 * @property int $id
 * @property int $school_id
 * @property int $campus_id
 * @property int $card_type_id
 * @property int $student_id
 * @property int $start_time
 * @property int $expire_time
 * @property int $total
 * @property int $residue
 * @property int $status
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 *
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard whereIn($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard leftJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard rightJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard get($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard first($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard select($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\StudentCard orderBy($column, $direction = 'asc')
 * @package App\Model
 */
class StudentCard extends BaseModel
{
    protected $table = 'student_card';

    protected $fillable = [
        "card_type_id", 'student_id', 'start_time', 'expire_time', 'total', 'residue', 'status', 'school_id', 'campus_id'
    ];


    public function attendances(){
        return $this->hasMany(Attendance::class);
    }

    public function card(){
        return $this->belongsTo(Card::class, 'card_type_id');
    }

    public function student()
    {
        return $this->belongsTo(Student::class);
    }

    public function getCardNameAttribute()
    {
        return $this->card['card_name'];
    }

    public function getTotalAttribute()
    {
        return (double) $this->attributes['total'];
    }

    public function getResidueAttribute()
    {
        return (double) $this->attributes['residue'];
    }
}
